package com.yystudy.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yystudy.model.system.SysPost;
import com.yystudy.model.vo.SysPostQueryVo;
import com.yystudy.system.mapper.SysPostMapper;
import com.yystudy.system.service.SysPostService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 岗位信息表 服务实现类
 * </p>
 *
 * @author yystudy
 * @since 2023-10-17
 */
@Service
public class SysPostServiceImpl extends ServiceImpl<SysPostMapper, SysPost> implements SysPostService {


    /**
     * 修改岗位状态
     * @param id
     * @param status
     */
    @Override
    public void updateStatusById(Long id, Integer status) {
        SysPost sysPost = baseMapper.selectById(id);
        sysPost.setStatus(status);
        baseMapper.updateById(sysPost);
    }


    /**
     * 岗位分页条件查询
     * @param pageParam
     * @param sysPostQueryVo
     * @return
     */
    @Override
    public IPage<SysPost> selectPage(Page<SysPost> pageParam, SysPostQueryVo sysPostQueryVo) {

        LambdaQueryWrapper<SysPost> lqw = new LambdaQueryWrapper<>();
        String postCode = sysPostQueryVo.getPostCode();
        String name = sysPostQueryVo.getName();
        Integer status = sysPostQueryVo.getStatus();
        if (!StringUtils.isEmpty(postCode)){
            lqw.like(SysPost::getPostCode,postCode);
        }
        if (!StringUtils.isEmpty(name)){
            lqw.like(SysPost::getName,name);
        }
        if (status != null){
            lqw.eq(SysPost::getStatus,status);
        }

        IPage<SysPost> sysPostPage = baseMapper.selectPage(pageParam, lqw);
        return sysPostPage;
    }



}
